package com.yeqifu.bus.controller;

import com.yeqifu.bus.domain.Car;
import com.yeqifu.bus.service.ICarService;
import com.yeqifu.bus.vo.CarVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * 车辆管理控制器
 */
@RestController
@RequestMapping("car")
public class CarController {

    @Autowired
    private ICarService carService;

    /**
     * 加载车辆列表返回DataGridView
     * @param car
     * @return
     */
    @RequestMapping("loadAllCar")
    public List<Car> selectCarList(Car car){
        return carService.selectCarList(car);
    }

    /**
     * 添加一个车辆
     * @param car
     * @return
     */
    @RequestMapping("addCar")
    public int addCar(Car car){
        car.setCreatetime(new Date());
       return carService.addCar(car);

    }

    /**
     * 修改一个车辆
     * @param car
     * @return
     */
    @RequestMapping("updateCar")
    public int updateCar(Car car){
        return carService.updateCar(car);
    }

    /**
     * 删除一个车辆
     * @param car
     * @return
     */
    @RequestMapping("deleteCar")
    public int deleteCar(Car car){
        return carService.deleteCar(car);
    }

    /**
     * 批量删除车辆
     * @param carVo
     * @return
     */
    @RequestMapping("deleteBatchCar")
    public void deleteBatchCar(CarVo carVo){
       carService.deleteBatchCar(carVo.getIds());
    }

}
